﻿using JinJun.YShowReception.Core;
using JinJun.YShowReception.DAL.IRepository;
using JinJun.YShowReception.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JinJun.YShowReception.DAL.Repository
{
    public class UserInfoRepository:IUserInfoRepository
    {
        /// <summary>
        /// 用户登录方法
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public UserInfo LoginUserInfo(UserInfo userInfo)
        {
            //sql语句
            string sql = "select Id,UserName,Pwd from UserInfo where UserName=@UserName and Pwd=@Pwd";           
            //调用查询方法
            UserInfo userInfo1 = DapperHelper<UserInfo>.QuerySingleOrDefault(sql, userInfo);
            return userInfo1;
        }


        /// <summary>
        /// 修改登录时间
        /// </summary>
        /// <param name="adminInfo"></param>
        /// <returns></returns>
        public int UpdateLoginTime(UserInfo userInfo)
        {
            int result = -1;
            //sql语句
            string sql = "update UserInfo set UpdateTime=@UpdateTime where UserName=@UserName";
            userInfo.UpdateTime = DateTime.Now;
            //调用修改方法
            int userInfo1 = DapperHelper<UserInfo>.Execute(sql, userInfo);
            return userInfo1;
        }


        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int AddUserInfo(UserInfo userInfo)
        {
            int result = -1;
            //sql语句
            string sql = "insert into UserInfo(UserName,Pwd,Phone,CreateTime) values(@UserName,@Pwd,@Phone,@CreateTime)";
            userInfo.CreateTime = DateTime.Now;
            //调用添加方法
            int userInfo1 = DapperHelper<UserInfo>.Execute(sql, userInfo);
            return userInfo1;
        }


        /// <summary>
        /// 查询手机号方法
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int CheckUserTel(UserInfo userInfo)
        {
            int result = -1;
            //sql语句
            string sql = "select Phone from UserInfo where Phone=@Phone";
            //调用查询方法
            UserInfo userInfo1 = DapperHelper<UserInfo>.QuerySingleOrDefault(sql, userInfo);
            if (userInfo1 != null)
            {
                result = 1;
            }
            return result;
        }



        /// <summary>
        /// 查询用户名方法
        /// </summary>
        /// <param name="userInfo"></param>
        /// <returns></returns>
        public int CheckUserName(UserInfo userInfo)
        {
            int result = -1;
            //sql语句
            string sql = "select UserName from UserInfo where UserName=@UserName";          
            //调用查询方法
            UserInfo userInfo1 = DapperHelper<UserInfo>.QuerySingleOrDefault(sql, userInfo);
            if (userInfo1 != null)
            {
                result = 1;
            }
            return result;
        }
    }
}
